
const loaderUtils = require('loader-utils');
// console.log(loaderUtils.getOptions(this));

const fs = require('fs');
const path = require('path');

module.exports = function(source) {
    const options = loaderUtils.getOptions(this);
    console.log(options.name);

    const json = JSON.stringify(source)
        .replace(/\u2028/g, '\\u2028')
        .replace(/\u2029/g, '\\u2029');
    // return `export default ${json}`;

    // 处理异常
    // throw new Error('error !!!');

    // this.callback(new Error('error'), `export default ${json}`);
    // this.callback(null, `export default ${json}`);

    const callback = this.async();
    fs.readFile(path.join(__dirname, './async.txt'), 
        'utf8', 
        (err, data) => {
            callback(err, data);
    });
}
